package com.xplay.xpocker.room.voice;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class UserConnectionStatus {
    private Map<String, Integer> connectionStatusMap;

    public UserConnectionStatus() {
        this.connectionStatusMap = new ConcurrentHashMap<>();
    }

    // 设置用户之间的连接状态
    public Integer getConnectionStatus(BigDecimal userIdA, BigDecimal userIdB) {
        String abkey = getKey(userIdA, userIdB);
        return connectionStatusMap.get(abkey);
    }

    private String getKey(BigDecimal userIdA, BigDecimal userIdB) {
        int comparisonResult = userIdA.compareTo(userIdB);
        String key;
        if (comparisonResult >= 0) {
            key = userIdB + "_" + userIdA;
        } else {
            key = userIdA + "_" + userIdB;
        }
        return key;
    }

    // 设置用户之间的连接状态
    public void setConnectionStatus(BigDecimal userIdA, BigDecimal userIdB, Integer status) {
        String key = getKey(userIdA, userIdB);
        connectionStatusMap.computeIfAbsent(key, k -> status);
    }

}
